<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取当前用户信息</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <style>
        #not_login, #div_logined {
            display: none;
        }
        #div_logined button{
            width: 200px;
            padding: 10px;
        }
    </style>
</head>
<body>
<div>
    <h1>用户信息</h1>
</div>

<div id="not_login">
    <span style="color: red;font-weight: bold;">未登陆</span>，<a href="/user/login">点击登陆</a>
</div>
<div id="div_logined">
    <div id="content1">

    </div>
    <button onclick="logout()">退出</button>
</div>
</body>
</html>

<script>
    var tokenKey = "tilesrowjwt";

    function fun1() {
        $.ajax({
            url: "/ucenter/info",
            headers: {
                'Accept': 'aplication/json',
                "tilesrowjwt": localStorage.getItem(tokenKey)
            },
            data: {
                a: 1
            },
            success: function (res) {
                if (res.state == "ok") {
                    localStorage.setItem(tokenKey, arguments[2].getResponseHeader(tokenKey));
                    $("#content1").text("用户信息：" + JSON.stringify(res));
                    $("#div_logined").show();
                    $("#not_login").hide();
                } else {
                    $("#not_login").show();
                    $("#div_logined").hide();
                }
            },
            error: function (a, b, c) {

            }
        })
    }

    fun1()

    function logout() {
        localStorage.removeItem(tokenKey);
        fun1();
    }
</script>